/*
 * Atomic Predicates for Transformers
 * 
 * Copyright (c) 2015 UNIVERSITY OF TEXAS AUSTIN. All rights reserved. Developed
 * by: HONGKUN YANG and SIMON S. LAM http://www.cs.utexas.edu/users/lam/NRL/
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * with the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * 1. Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimers.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimers in the documentation
 * and/or other materials provided with the distribution.
 * 
 * 3. Neither the name of the UNIVERSITY OF TEXAS AUSTIN nor the names of the
 * developers may be used to endorse or promote products derived from this
 * Software without specific prior written permission.
 * 
 * 4. Any report or paper describing results derived from using any part of this
 * Software must cite the following publication of the developers: Hongkun Yang
 * and Simon S. Lam, Scalable Verification of Networks With Packet Transformers
 * Using Atomic Predicates, IEEE/ACM Transactions on Networking, October 2017,
 * Volume 25, No. 5, pages 2900-2915 (first published as IEEE Early Access
 * Article, July 2017, Digital Object Identifier: 10.1109/TNET.2017.2720172).
 * 
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
 * THE SOFTWARE.
 */
package transformer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import jdd.util.jre.JREInfo;
import common.FWDAPSet;
import common.PositionTuple;


public class MemoryTest {

    public static void testI2MPLS() throws IOException
    {
        JREInfo.show();

        NetworkMPLSAP net_mpls_ap = new NetworkMPLSAP("i2");

        for(Box b : net_mpls_ap.boxes.values())
        {
            ((Device) b).fws = null;
        }

        net_mpls_ap.read_tunnels_from_file("i2_unique_tunnels");

        net_mpls_ap.ap_mpls(28);

        JREInfo.show();

        ArrayList<StateAP> states = new ArrayList<StateAP> ();

        HashSet<PositionTuple> pts = net_mpls_ap.getallactiveports();
        for(PositionTuple pt : pts)
        {
            FWDAPSet non_mpls_pkts = net_mpls_ap.bddengine.get_nonmpls_pkts_ap(net_mpls_ap.apc);
            StateTransferAP stfer = new StateTransferAP(net_mpls_ap);
            states.add(stfer.Traverse(pt, non_mpls_pkts));
        }

        JREInfo.show();
    }

    public static void testCOVEMPLS() throws IOException
    {
        String as_name = "52941"; //"37684";
        String tunnel_file = "52941_52941_mpls_tunnels"; //"37684_mpls_tunnels";

        JREInfo.show();

        NetworkCOVEMPLSAP net_mpls_ap = new NetworkCOVEMPLSAP(as_name, null, as_name);


        net_mpls_ap.read_tunnels_from_file(tunnel_file);
        net_mpls_ap.ap_mpls(40);


        JREInfo.show();


        /*
        HashSet<PositionTuple> pts = net_mpls_ap.getallactiveports();
        ArrayList<PositionTuple> used_pt = new ArrayList<PositionTuple>();
        ArrayList<StateAP> states = new ArrayList<StateAP> ();

        for(PositionTuple pt : pts)
        {
            if(pt.getPortName().equals(net_mpls_ap.root_as))
            {
                used_pt.add(pt);
                System.out.println(pt + " selected");
            }
        }

        for(PositionTuple pt : pts){
            FWDAPSet non_mpls_pkts = net_mpls_ap.bddengine.get_nonmpls_pkts_ap(net_mpls_ap.apc);
            StateTransferAP stfer = new StateTransferAP(net_mpls_ap);
            StateAP s = stfer.Traverse(pt, non_mpls_pkts);
            states.add(s);
        }*/
        
        //two ports: 
        //PositionTuple pt = new PositionTuple("28666", "52941");
        PositionTuple pt = new PositionTuple("22177", "52941");
        FWDAPSet non_mpls_pkts = net_mpls_ap.bddengine.get_nonmpls_pkts_ap(net_mpls_ap.apc);
        StateTransferAP stfer = new StateTransferAP(net_mpls_ap);
        StateAP s = stfer.Traverse(pt, non_mpls_pkts);
        JREInfo.show();

    }

    public static void main(String[] args) throws IOException
    {

        testCOVEMPLS();
    }

}
